<html><body><div class="content"><div class="section" id="the-while-statement">
<span id="while"></span><h2>The <a class="reference internal" href="#while"><tt class="xref std std-keyword docutils literal"><span class="pre">while</span></tt></a> statement</h2>
<p id="index-4">The <a class="reference internal" href="#while"><tt class="xref std std-keyword docutils literal"><span class="pre">while</span></tt></a> statement is used for repeated execution as long as an
expression is true:</p>
<pre>
<strong id="grammar-token-while_stmt">while_stmt</strong> ::=  &quot;while&quot; <a class="reference internal" href="expressions.html#grammar-token-expression"><tt class="xref docutils literal"><span class="pre">expression</span></tt></a> &quot;:&quot; <a class="reference internal" href="#grammar-token-suite"><tt class="xref docutils literal"><span class="pre">suite</span></tt></a>
                [&quot;else&quot; &quot;:&quot; <a class="reference internal" href="#grammar-token-suite"><tt class="xref docutils literal"><span class="pre">suite</span></tt></a>]
</pre>
<p>This repeatedly tests the expression and, if it is true, executes the first
suite; if the expression is false (which may be the first time it is tested) the
suite of the <a class="reference internal" href="#else"><tt class="xref std std-keyword docutils literal"><span class="pre">else</span></tt></a> clause, if present, is executed and the loop
terminates.</p>
<p id="index-5">A <a class="reference internal" href="simple_stmts.html#break"><tt class="xref std std-keyword docutils literal"><span class="pre">break</span></tt></a> statement executed in the first suite terminates the loop
without executing the <a class="reference internal" href="#else"><tt class="xref std std-keyword docutils literal"><span class="pre">else</span></tt></a> clause&#8217;s suite.  A <a class="reference internal" href="simple_stmts.html#continue"><tt class="xref std std-keyword docutils literal"><span class="pre">continue</span></tt></a>
statement executed in the first suite skips the rest of the suite and goes back
to testing the expression.</p>
</div>
</div></body></html>
